package top.topsmart.api.bycenter.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.topsmart.api.bycenter.model.Info;
import top.topsmart.api.bycenter.service.WechatService;
import top.topsmart.api.bycenter.util.Result;

import java.text.SimpleDateFormat;
import java.util.Date;

@Api(tags = "微信小程序登录")
@RestController
@RequestMapping(value = "login",method = {RequestMethod.GET})
public class LoginController {
    @Autowired
    private WechatService wechatService;

    @ApiOperation("login")
    @GetMapping("index")
    public Result login(String code) throws Exception{
        System.out.println(new SimpleDateFormat("yyy-MM-dd hh:mm:ss").format(new Date()) + "  正在处理login/release");
        return wechatService.login(code);
    }

    @ApiOperation("getInfo")
    @GetMapping("getInfo")
    public Info getInfo(@RequestParam(value = "infoId") String infoId) throws Exception{
        System.out.println(new SimpleDateFormat("yyy-MM-dd hh:mm:ss").format(new Date()) + "  正在处理login/release");
        return wechatService.getInfo(infoId);
    }

    @ApiOperation("reload")
    @GetMapping("reload")
    public Result reload(@RequestParam(value = "userId") String userid) throws Exception{
        System.out.println(new SimpleDateFormat("yyy-MM-dd hh:mm:ss").format(new Date()) + "  正在处理login/reload");
        return wechatService.reload(userid);
    }
}
